from rest_framework import serializers

from apps.goods.models import SPU, GoodsCategory


class SPUSerializer(serializers.ModelSerializer):
    brand = serializers.StringRelatedField(read_only=True)
    brand_id = serializers.IntegerField()
    category1 = serializers.StringRelatedField(read_only=True)
    category2 = serializers.StringRelatedField(read_only=True)
    category3 = serializers.StringRelatedField(read_only=True)
    category1_id = serializers.IntegerField()
    category2_id = serializers.IntegerField()
    category3_id = serializers.IntegerField()
    class Meta:
        model = SPU
        fields = '__all__'
        # read_only_fields = ['desc_detail','desc_pack','desc_service']
#获取品牌信息
class GoodsBrandSimpleSerializer(serializers.Serializer):
    id = serializers.IntegerField()
    name = serializers.CharField(read_only=True)
#获取一级分类信息
class CategorySerilaizer(serializers.Serializer):
    id = serializers.IntegerField()
    name = serializers.StringRelatedField(read_only=True)

#获取三级分类标题
class ThreeCategorySerializer(serializers.Serializer):
    id = serializers.IntegerField()
    name = serializers.StringRelatedField(read_only=True)
#获取二级分类标题
class SubsCategorySerializer(serializers.Serializer):
    id = serializers.IntegerField()
    name = serializers.StringRelatedField(read_only=True)
    subs = ThreeCategorySerializer(read_only=True,many=True)
# 得到二级标题
class TwoCategorySerilaizer(serializers.Serializer):
    id = serializers.IntegerField()
    name = serializers.StringRelatedField(read_only=True)
    subs = SubsCategorySerializer(read_only=True,many=True)
